package com.hourse.platform.utils;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

/**
 * @使用描述: CurrentThread
 */
public class CurrentThread {


  private final static ThreadLocal<HashMap<String,Object>> valueMap = new ThreadLocal<>();

  public static void put(String key,Object value){
    if(valueMap.get() == null){
      valueMap.set(new HashMap<>());
    }
    valueMap.get().put(key,value);
  }

  public static Object get(String key){

    return valueMap.get().get(key);
  }

  public static void remove(String key){

    valueMap.get().remove(key);
  }

  public static void setUserId(String userId){
    valueMap.get().put("_userId",userId);
  }

  public static String getUserId(){
    return
            valueMap.get() !=null
            && valueMap.get().
            containsKey("_userId") ? (String)valueMap.get().get("_userId") : "";
  }

  public static void setToken(String userId){
    valueMap.get().put("token",userId);
  }

  public static String getToken(){
    return (String)valueMap.get().get("token");
  }

 /* public static void setRoleGroupId(String userId,String roleGroupId){
    valueMap.get().put(userId + "_roleGroupId",roleGroupId);
  }

  public static String getRoleGroupId(){
    return (String)valueMap.get().get(getUserId() + "_roleGroupId");
  }
*/
  public static boolean isAdmin() {

    if(valueMap.get().get("_admin") == null){

      return false;
    }

    return (boolean)valueMap.get().get("_admin");
  }

  public static void setAdminStatus(boolean status) {
    valueMap.get().put("_admin",status);
  }

  public static void setRoles(Set<String> roles) {
    valueMap.get().put("_roles",roles);
  }

  public static Set<String> getRoles() {

    if(valueMap.get() == null){
        return new HashSet<>();
    }
    return (Set<String>)valueMap.get().get("_roles");
  }

    public static void setCurrentRoleId(String roleGroupId) {
        valueMap.get().put("role_id",roleGroupId);
    }

    public static String getCurrentRoleId() {
        return (String) valueMap.get().get("role_id");
    }

    public static void setCurrentEnterPriseId(String eid) {
        valueMap.get().put("curt_eid",eid);
    }
    public static String getCurrentEnterPriseId() {
        return (String)valueMap.get().get("curt_eid");
    }

}
